package fr.univsavoie.tatiana2dvisualisation;

import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.Vector;

import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPartFactory;
import org.eclipse.gef.editparts.AbstractGraphicalEditPart;

import fr.emse.tatiana.replayable.IReplayableModel;

public class EyeTrackerPartFactory implements EditPartFactory {

	private Map<Object,EditPart> objectmap;
	private List<DrawCondition> conditions;

	public EyeTrackerPartFactory(Vector<DrawCondition> conditions) {
		super();
		objectmap = new Hashtable<Object, EditPart>();
		this.conditions = conditions;
	}

	public EditPart createEditPart(EditPart context, Object model) {

		AbstractGraphicalEditPart part = null; 

		if (objectmap.containsKey(model)) {
			return objectmap.get(model);
		}

		if (model instanceof IReplayableModel) {
			part = new EyeTrackerModelPart((IReplayableModel) model, conditions);
		} else {
			part = new EyeTrackerEventPart((EyeTrackerEvent) model);
		} 

		part.setParent(context);
		objectmap.put(model,part);

		return part;
	}

	public EditPart getEditPart(Object model) {
		return objectmap.get(model);
	}

}
